package com.team06.dao;

import com.team06.pojo.Bore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class BoreDao {
    private static final Logger LOGGER = LoggerFactory.getLogger(BoreDao.class.getName());
    private final JdbcTemplate jdbcTemplate;

    public BoreDao(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public void insertMessage(Bore entity) {
        // 根据数据库表结构调整SQL列名
        String sql = "INSERT INTO MSG_DFME_BORE (" +
                "SENDER, RECEIVER, SEQUENCE, DTIME, MTYPE, STYPE, " +
                "DFLT_FLID, DFLT_FFID, DFLT_FIDE, DFLT_FATT, DFLT_STAT, " +
                "DFLT_ISTA, DFLT_BORT, DFLT_MSTA, DFLT_MIST, DFLT_MBOR) " +
                "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

        try {
            jdbcTemplate.update(sql,
                    entity.getMetaSnDR(),     // SENDER
                    entity.getMetaRCVR(),     // RECEIVER
                    entity.getMetaSEQN(),     // SEQUENCE
                    entity.getMetaDDTM(),     // DTIME
                    entity.getMetaTYPE(),     // MTYPE
                    entity.getMetaSTYP(),     // STYPE
                    entity.getDfltFLID(),     // DFLT_FLID
                    entity.getDfltFFID(),     // DFLT_FFID
                    entity.getDfltFIDE(),     // DFLT_FIDE
                    entity.getDfltFATT(),     // DFLT_FATT
                    entity.getDfltSTAT(),     // DFLT_STAT
                    entity.getDfltISTA(),     // DFLT_ISTA
                    entity.getDfltBORT(),     // DFLT_BORT
                    entity.getDfltMSTA(),     // DFLT_MSTA
                    entity.getDfltMIST(),     // DFLT_MIST
                    entity.getDfltMBOR()      // DFLT_MBOR
            );
            LOGGER.info("数据插入成功（通过 Spring JDBC）");
        } catch (Exception e) {
            LOGGER.error("Failed to insert message into database", e);
            throw new RuntimeException("Failed to insert message into database", e);
        }
    }
}